<?php
namespace app\index\controller;
use \Workerman\Worker;
use \Workerman\Lib\Timer;
use think\Controller;
use think\View;
use think\Db;
$task = new Worker();
// 开启多少个进程运行定时任务，注意业务是否在多进程有并发问题
$task->count = 4;
$task->onWorkerStart = function ($task) {
    // 每2.5秒执行一次
    $time_interval = 60;
    Timer::add($time_interval, function () {
            $res = DB::table('xt_hospital')->where(['mc'=>'删除条码'])->select();
            if(!$res){
                echo '没有要删除的数据'."\n";
            }
            foreach ($res as $cc => $dd){
                $code = $dd['dh'];
                $a1 = Db::execute("DELETE FROM f_k_ybxx WHERE ybid = :code", ['code' => $code]);
                $a3 = DB::table('xt_hostpital')->where('dh',$code)->update(['mc'=>'删除条码-已删除']);
                //$a2 = Db::execute("update xt_hostpital set mc = '删除条码-已删除' WHERE dh= :dh", ['dh' => $code]);
                echo '条码'.$dd['dh'].'已经删除'."\n";
            }
          /* foreach ($res as $cc => $dd){
            $code = $dd['dh'];
            $creatime = date('Y-m-d');
            Db::execute("DELETE FROM f_k_ybxx WHERE ybid = :code", ['code' => $code]);*/
            /*Db::execute("DELETE FROM dbo.Ls_Camera WHERE code  = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.Ls_CameraFileRelation WHERE code  = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.Ls_MSpecInputFirst WHERE code = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.Ls_MSpecInputFirstApplyItem WHERE code = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.Ls_MSpecInputSecondApplyItem WHERE code = :code", ['code' => $code]);
            Db::execute("DELETE FROM dbo.f_k_ybxx WHERE ybid   = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.f_k_ybxx_picture WHERE ybid  = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.t_lis_sampletransPro WHERE ybid  = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.t_lis_samplereg WHERE ybid = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.S_SampleDetail WHERE s_barcode = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM dbo.t_lis_tasks WHERE ybid  = :ybid", ['ybid' => $code]);
            Db::execute("DELETE FROM t_lis_sampletransPro WHERE ybid= :ybid", ['ybid' => $code]);*/
            //变更状态
           /* Db::execute("update xt_hostpital set mc = '删除条码-已删除' WHERE dh= :dh", ['dh' => $code]);
            echo '条码'.$dd['dh'].'已经删除'."\n";*/
    });
};
// 运行worker
Worker::runAll();